FROM hxsoong/kylin:v10-sp3
MAINTAINER Wang Wei<wangwii@foxmail.com>

# Install sshd and jdk
RUN dnf clean all && dnf makecache && dnf -y update && \
    dnf -y install lsof passwd vi unzip net-tools iputils iproute \
           openssh-server openssh-clients java-1.8.0-openjdk && \
    dnf autoremove && dnf clean all && rm -rf /var/cache/dnf/*

# Setup bash shell and env
ENV SHELL=/bin/bash TZ=Asia/Beijing
COPY etc/profile.d/* /etc/profile.d/

# Enable python and systemd
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 150
COPY systemctl-replacement/systemctl3.py /usr/bin/systemctl3.py
RUN mv /usr/bin/systemctl /usr/bin/systemctl_old && cp /usr/bin/systemctl3.py /usr/bin/systemctl

# Setup sshd.service
RUN sed -i '/RSAAuthentication/s/^/#/' /etc/ssh/sshd_config
# RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
# RUN sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config

RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" && \
    ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" && \
    ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""

RUN systemctl enable sshd-keygen.target --force
RUN systemctl enable sshd.service

EXPOSE 22

CMD /usr/bin/systemctl init sshd.service
